package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exception.LyException;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName : SpecParamServiceImpl  //类名
 * @Description : 规格参数servic实现类  //描述
 * @Author : qingfeng  //作者
 * @Date: 2020-09-17 20:31  //时间
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    @Override
    public List<SpecParamDTO> querySpecParams(Long categoryId, Long groupId, Boolean searching) {
        /**
         * @Description //TODO 查询规格参数集合
         * @Param [categoryId, groupId, searching]
         * @return java.util.List<com.leyou.item.dto.SpecParamDTO>
         */
        //健壮性判断
        if (categoryId == null && groupId == null) {
            //条件不能为空
            throw new LyException(400,"查询条件不能为空!");
        }
        //查询
        List<SpecParam> list = query()
                .eq(categoryId != null, "category_id", categoryId)
                .eq(groupId != null, "group_id", groupId)
                .eq(searching != null, "searching", searching)
                .list();
        return SpecParamDTO.convertEntityList(list);
    }
}
